package com.openx.xoj.service.impl;

import com.openx.xoj.mapper.ExaminationMapper;
import com.openx.xoj.model.Teacher.Examination;
import com.openx.xoj.service.ExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExaminationServiceImpl implements ExaminationService {

    @Autowired
    private ExaminationMapper examinationMapper;

    @Override
    @Transactional
    public int createExamination(Examination examination) {
        examinationMapper.insertExamination(examination);
        return examination.getId();  // 获取自动生成的ID
    }

    @Override
    public List<Examination> getAllExaminations() {
        return examinationMapper.findAll();
    }

    @Override
    public boolean deleteExaminationById(Integer id) {
        return examinationMapper.deleteExaminationById(id) > 0;
    }

    @Override
    public boolean updateExaminationById(Examination examination) {
        return examinationMapper.updateExamination(examination) > 0;
    }

    @Override
    public int getLastExaminationId() {
        return examinationMapper.getLastExaminationId();
    }
}
